package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.DeviceDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *@Author: 布莱恩
 *@Date: 2025/10/20 17:12
 *@Description:
 **/
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "智能设备的接口")
public class DeviceController extends BaseController {

    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备列表
     * @param device
     * @return
     */
    @PreAuthorize("@ss.hasPermi('elder:device:list')")
    @GetMapping("/list")
    @ApiOperation("查询设备列表")
    public TableDataInfo list(Device device) {
        startPage();
        List<Device> devices = deviceService.selectDeviceList(device);
        return getDataTable(devices);
    }

    /**
     * 同步产品列表
     * @return
     */
    @GetMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public AjaxResult syncProductList() {
        deviceService.syncProductList();
        return success("同步成功");
    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    @ApiOperation("查询所有产品列表")
    public AjaxResult allProduct() {
        return success(deviceService.allProduct());
    }

    /**
     * 设备注册
     * @param deviceDto
     * @return
     */
    @PostMapping("/register")
    @ApiOperation("设备注册")
    public AjaxResult register(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return success();
    }

    /**
     * 查询设备详情
     * @param deviceDto
     * @return
     */
    @PostMapping("/queryDeviceDetail")
    public R<DeviceDetailVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        DeviceDetailVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return R.ok(deviceVo);
    }

    /**
     * 查询物模型发布状态
     * @param deviceDto
     * @return
     */
    @PostMapping("/queryThingModelPublished")
    public AjaxResult queryThingModelPublished(@RequestBody DeviceDto deviceDto) {
        return success(deviceService.queryThingModelPublished(deviceDto));
    }

}
